<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- fontawesome Icons 图标库 -->
    <link rel="stylesheet" href="../public_static/fontawesome/css/all.css">
    <title>现代博客系统</title>
    <!-- 鼠标点击文字显示效果css代码-->
    <link rel="stylesheet" href="../public_static/css/mouse_click_effect.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: sans-serif;
        }

        body {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-content: center;
        }

        /* 导航栏样式 */
        .navbar {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
            padding: 1rem;
            margin: 0 5rem;
        }

        .navbar .navbar_title {
            font-size: 1.5rem;
            text-decoration: none;
            color: inherit;
            cursor: pointer;
            display: flex;
            flex-direction: row;
            gap: 0.5rem;
            justify-content: center;
            align-items: center;
        }

        .navbar .nav_right {
            font-size: 1rem;
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
            gap: 2rem;
        }

        .navbar .nav_right .nav_item {
            font-size: 1rem;
            color: inherit;
            text-decoration: none;
            cursor: pointer;
        }

        .navbar .nav_right .nav_item:hover {
            cursor: pointer;
            color: rgb(13, 110, 253);
        }

        /* 主页内容区域样式 */
        .homepage {
            background-color: rgb(248, 249, 250);
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: flex-start;
            padding: 1rem 6rem;
            width: 100%;
            gap: 2.5rem;
        }

        /* 文章列表展示区域样式 */
        .homepage .content_show {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            gap: 1rem;
            flex: 1;
            width: 100%;
        }

        /* 搜索框样式 */
        .homepage .content_show .search_input {
            width: 60%;
            display: flex;
            flex-direction: row;
            margin: 1rem 0;
        }

        .homepage .content_show .search_input input {
            width: 100%;
            padding: 10px;
            border-radius: 8px;
        }

        .homepage .content_show .search_input button {
            min-width: fit-content;
            padding: 0.25rem 0.5rem;
            margin-left: 0.5rem;
            border-radius: 8px;
            cursor: pointer;
        }

        /* 文章卡片容器样式 */
        .homepage .content_show .article_card {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            gap: 1rem;
        }

        /* 文章卡片内容样式 */
        .homepage .content_show .article_card .article_content {
            background-color: white;
            padding: 1rem;
            border-radius: 0.5rem;
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
            gap: 1rem;
            transition: transform 0.3s ease;
            min-height: 250px;
        }

        /* 文章卡片悬停效果 */
        .homepage .content_show .article_card .article_content:hover {
            transform: translateY(-3px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }

        /* 文章图片样式 */
        .homepage .content_show .article_card .article_content .article_pic {
            width: 50%;
            height: 170px;
        }

        .homepage .content_show .article_card .article_content .article_pic img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            object-position: center;
            border-radius: 8px;
            display: block;
        }

        /* 文章信息样式 */
        .homepage .content_show .article_card .article_content .article_info {
            display: flex;
            flex-direction: column;
            justify-self: start;
            gap: 5px;
            width: 45rem;
        }

        .homepage .content_show .article_card .article_content .article_info .article_card_top {
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            align-items: center;
            gap: 13px;
        }
        .homepage .content_show .article_card .article_content .article_info .article_card_top .article_category {
            background-color: rgb(13, 202, 240);
            border-radius: 8px;
            padding: 2.5px 5px;
        }

        .homepage .content_show .article_card .article_content .article_info .article_title {
            font-size: 2rem;
            font-weight: bolder;
        } 

        .homepage .content_show .article_card .article_content .article_info .article_expert {
            margin: 10px 0;
        }

        .homepage .content_show .article_card .article_content .article_info .article_author {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
        }

        .homepage .content_show .article_card .article_content .article_info .article_author .article_card_bottom {
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            align-items: center;
            gap: 10px;
        }

        .homepage .content_show .article_card .article_content .article_info .article_author .article_card_bottom img {
            border-radius: 50%;
            width: 30px;
            height: 30px;
            object-fit: cover;
        }

        /* 阅读更多按钮样式 */
        .homepage .content_show .article_card .article_content .article_info .article_author .reading_more {
            text-decoration: none;
            align-content: center;
            color: inherit;
            cursor: pointer;
            padding: 5px 10px;
            color: rgb(13, 110, 253);
            border: 1px solid rgb(13, 110, 253);
            border-radius: 8px;
        }

        .homepage .content_show .article_card .article_content .article_info .article_author .reading_more:hover {
            background-color: rgb(13, 110, 253);
            color: white;
        }

        /* 分页导航样式 */
        .homepage .content_show .pagenav {
            display: flex;
            flex-direction: row;
            gap: 10px;
            margin: 1rem 0;
        }

        .homepage .content_show .pagenav a {
            text-decoration: none;
            color: inherit;
            padding: 5px 10px;
            background-color: rgb(13, 110, 253);
            color: white;
            border-radius: 8px;
            font-size: 1.2rem;
        }

        .homepage .content_show .pagenav a:hover {
            background-color: white;
            color: rgb(13, 110, 253);
            border: 1px solid rgb(13, 110, 253);
            box-sizing: border-box;
        }


        /* 文章详情页样式 */
        .homepage .article_detail {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
            gap: 1rem;
            flex: 1;
            margin-top: 2rem;
            max-width: 700px;
        }

        /* 返回列表按钮样式 */
        .homepage .article_detail .fhwzlb {
            text-decoration: none;
            color: white;
            border-radius: 8px;
            padding: 8px 10px;
            background-color: rgb(13, 110, 253);
        }

        .homepage .article_detail .fhwzlb:hover {
            color: rgb(13, 110, 253);
            background-color: white;
            border: 1px solid rgb(13, 110, 253);
            box-sizing: border-box;
        }

        .homepage .article_detail .title_info {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
        }

        .homepage .article_detail .title_info .wzbt {
            font-size: 2rem;
            font-weight: bolder;
        }

        .homepage .article_detail .title_info .wzxx {
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
            gap: 2.5rem;
            margin: 1rem 0;
        }

        .homepage .article_detail .title_info .wzxx .wzxx_author {
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }

        .homepage .article_detail .title_info .wzxx .wzxx_author img {
            border-radius: 50%;
            width: 30px;
            height: 30px;
            object-fit: cover;
        }

        .homepage .article_detail .title_info .wzxx .wzxx_group {
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: center; 
            gap: 10px;
        }

        .homepage .article_detail .article_content {
            width: 100%;
        }

        /* 右侧边栏样式 */
        .homepage .right_bar {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
            gap: 2rem;
        }

        /* 作者信息样式 */
        .homepage .right_bar .author_info {
            background-color: white;
            display: flex;
            flex-direction: column;
            width: 20rem;
            padding: 1.5rem;
            border-radius: 10px;
            gap: 1rem;
        }

        .homepage .right_bar .author_info .zzxx_img {
            height: 200px;
            display: flex;
            flex-direction: row;
            align-items: center;
            justify-content: center;
        }

        .homepage .right_bar .author_info .zzxx_img img {
            width: 200px;
            height: 200px;
            border-radius: 50%;
            object-fit: cover;
            border: 3px solid #fff;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        }

        .homepage .right_bar .author_info .zzxx_intro {
            text-align: center;
        }

        /* 联系信息样式 */
        .homepage .right_bar .author_info .lxxx {
            position: relative;
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
            gap: 1rem;
        }

        .homepage .right_bar .author_info .lxxx .social-item {
            position: relative;
            display: inline-block;
        }

        .homepage .right_bar .author_info .lxxx .social-item a {
            text-decoration: none;
            color: inherit;
            font-size: larger;
        }

        .homepage .right_bar .author_info .lxxx .social-item a:hover {
            color: rgb(13, 110, 253);
        }

        /* 二维码悬停显示样式 */
        .homepage .right_bar .author_info .lxxx .social-item .qrcode {
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            padding: 10px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
            z-index: 100;
            display: none;
            margin-bottom: 10px;
        }

        .homepage .right_bar .author_info .lxxx .social-item .qrcode img {
            width: 120px;
            height: 120px;
            display: block;
        }

        .homepage .right_bar .author_info .lxxx .social-item:hover .qrcode {
            display: block;
        }

        .homepage .right_bar .author_info .lxxx .social-item .qrcode::after {
            content: '';
            position: absolute;
            top: 100%;
            left: 50%;
            margin-left: -5px;
            border-width: 5px;
            border-style: solid;
            border-color: white transparent transparent transparent;
        }

        /* 文章分类样式 */
        .homepage .right_bar .wzfl {
            background-color: white;
            display: flex;
            flex-direction: column;
            width: 20rem;
            padding: 1.25rem;
            border-radius: 10px;
            gap: 1rem;
        }

        .homepage .right_bar .wzfl .wzfl_title {
            display: flex;
            flex-direction: row;
            gap: 5px;
            justify-content: flex-start;
            align-items: center;
        }

        .homepage .right_bar .wzfl .wzfl_content {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
            gap: 5px;
        }

        .homepage .right_bar .wzfl .wzfl_content .wzfl_info {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: flex-start;
            width: 100%;
        }

        .homepage .right_bar .wzfl .wzfl_content .wzfl_info a {
            display: flex;
            flex-direction: row;
            justify-content: center;
            align-items: center;
            text-decoration: none;
            color: inherit;
            cursor: pointer;
            gap: 5px;
        }

        .homepage .right_bar .wzfl .wzfl_content .wzfl_info a:hover {
            color: rgb(13, 110, 253);
        }

        .homepage .right_bar .wzfl .wzfl_content .wzfl_info .number {
            padding: 2.5px 10px;
            color: white;
            border-radius: 8px;
        }

        /* 热门文章样式 */
        .homepage .right_bar .lmwz {
            background-color: white;
            display: flex;
            flex-direction: column;
            width: 20rem;
            padding: 1.25rem;
            border-radius: 10px;
            gap: 1rem;
        }

        .homepage .right_bar .lmwz .lmwz_title {
            display: flex;
            flex-direction: row;
            gap: 5px;
            justify-content: flex-start;
            align-items: center;
        }

        .homepage .right_bar .lmwz .lmwz_content {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
            gap: 5px;
        }

        .homepage .right_bar .lmwz .lmwz_content .lmwz_new {
            border-bottom: 1px solid gray;
            width: 100%;
            padding: 0.5rem 0;
            display: flex;
            flex-direction: column;
            gap: 5px;
        }

        .homepage .right_bar .lmwz .lmwz_content .lmwz_new a {
            text-decoration: none;
            color: inherit;
            cursor: pointer;
        }

        .homepage .right_bar .lmwz .lmwz_content .lmwz_new a:hover {
            color: rgb(13, 110, 253);
        }

        /* 标签云样式 */
        .homepage .right_bar .bqy {
            background-color: white;
            display: flex;
            flex-direction: column;
            width: 20rem;
            padding: 1.25rem;
            border-radius: 10px;
            gap: 1rem;
        }

        .homepage .right_bar .bqy .bqy_title {
            display: flex;
            flex-direction: row;
            gap: 5px;
            justify-content: flex-start;
            align-items: center;
        }

        .homepage .right_bar .bqy .bqy_content {
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            align-items: center;
            flex-wrap: wrap;
            gap: 5px;
        }

        .homepage .right_bar .bqy .bqy_content .bqy_item {
            padding: 2.5px 8px;
            background-color: rgb(13, 110, 253);
            color: white;
            border-radius: 8px;
        }

        .homepage .right_bar .bqy .bqy_content .bqy_item:hover {
            cursor: pointer;
            background-color: white;
            color: rgb(13, 110, 253);
            border: 1px solid rgb(13, 110, 253);
            border-radius: 8px;
            box-sizing: border-box;
        }

        /* 页脚样式 */
        footer {
            padding: 4rem 0 2rem 0;
            background-color: rgb(248,249,250);
            text-align: center;
        }

    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar">
        <a class="navbar_title" href="#" title="点击返回首页" id="navbarTitle">
            <i class="fas fa-file-text"></i>
            <div class="name">博客空间</div>
        </a>
        <div class="nav_right" id="navRight">
            <a href="#" class="nav_item">首页</a>
            <a href="#" class="nav_item">技术</a>
            <a href="#" class="nav_item">生活</a>
            <a href="#" class="nav_item">旅行</a>
            <a href="#" class="nav_item">美食</a>
        </div>
    </nav>

    <!-- 正文内容 -->
    <section class="homepage">
        <!-- 文章列表展示区域 -->
        <div class="content_show" id="contentShow">
            <!-- 搜索框容器 -->
            <div class="search_input" id="searchInputContainer">
                <input type="text" placeholder="搜索文章..." id="searchInput">
                <button id="searchBtn">搜索</button>
            </div>
            <!-- 文章卡片容器 -->
            <div class="article_card" id="articleCardContainer">
                <!-- 卡片信息通过js代码动态加载 -->
            </div>
            <!-- 分页导航容器 -->
            <div class="pagenav" id="paginationContainer">
           
            </div>
        </div>

        <!-- 文章详情页 -->
        <div class="article_detail" id="articleDetail" style="display: none;">
            <a href="#" class="fhwzlb" id="backToListBtn">返回文章列表</a>
            <div class="title_info" id="articleTitleInfo">
                <div class="wzbt" id="articleTitle"></div>
                <div class="wzxx" id="articleMetaInfo">
                    <div class="wzxx_author" id="articleAuthorInfo">
                        <img src="" alt="作者头像" id="authorAvatar">
                        <div id="authorName"></div>
                    </div>
                    <div class="wzxx_group" id="publishDateGroup">
                        <i class="fas fa-calendar"></i>
                        <div class="wzxx_item" id="publishDate"></div>
                    </div>
                    <div class="wzxx_group" id="readTimeGroup">
                        <i class="fas fa-clock"></i>
                        <div class="wzxx_item" id="readTime"></div>
                    </div>
                    <div class="wzxx_group" id="viewCountGroup">
                        <i class="fas fa-eye"></i>
                        <div class="wzxx_item" id="viewCount"></div>
                    </div>
                </div>
            </div>
            <!-- 通过js代码加载文章内容 -->
            <div class="article_content" id="articleContent"></div>
        </div>

        <!-- 右侧边栏 -->
        <div class="right_bar" id="rightBar">
            <!-- 作者信息 -->
            <div class="author_info" id="authorInfo">
                <div class="zzxx_img">
                    <img src="./static/images/article_pic/个人照片.jpg" alt="博客开发者照片">
                </div>
                <div class="zzxx_intro">
                    热爱生活，喜欢分享的创作者。专注于技术、生活、旅行和美食领域。
                </div>
                <div class="lxxx">
                    <div class="social-item">
                        <a href="#"><i class="fab fa-weixin"></i></a>
                        <div class="qrcode">
                            <img src="./static/images/qrcode/weixin.png" alt="微信二维码">
                        </div>
                    </div>
                    <div class="social-item">
                        <a href="#"><i class="fab fa-qq"></i></a>
                        <div class="qrcode">
                            <img src="./static/images/qrcode/qq.png" alt="QQ二维码">
                        </div>
                    </div>
                    <div class="social-item">
                        <a href="#"><i class="fa fa-envelope"></i></a>
                        <div class="qrcode">
                            <img src="./static/images/qrcode/qqemail.png" alt="邮箱二维码">
                        </div>
                    </div>
                </div>
            </div>
            <!-- 文章分类 -->
            <div class="wzfl" id="categoryContainer">
                <div class="wzfl_title"><i class="fas fa-folder"></i>文章分类</div>
                <div class="wzfl_content" id="categoryContent">
                    <!-- 通过js代码加载 -->
                </div>
            </div>
            <!-- 热门文章 -->
            <div class="lmwz" id="popularArticlesContainer">
                <div class="lmwz_title"><i class="fas fa-fire"></i>热门文章</div>
                <div class="lmwz_content" id="popularArticlesContent">
                    <!-- 通过js代码加载 -->
                </div>
            </div>
            <!-- 标签云 -->
            <div class="bqy" id="tagsContainer">
                <div class="bqy_title"><i class="fas fa-tags"></i>标签云</div>
                <div class="bqy_content" id="tagsContent">
                    <div class="bqy_item">JavaScript</div>
                    <div class="bqy_item">Flask</div>
                    <div class="bqy_item">旅行</div>
                    <div class="bqy_item">摄影</div>
                    <div class="bqy_item">极简主义</div>
                    <div class="bqy_item">人工智能</div>
                    <div class="bqy_item">健康</div>
                    <div class="bqy_item">读书</div>
                    <div class="bqy_item">CSS3</div>
                    <div class="bqy_item">HTML5</div>
                    <div class="bqy_item">Electron</div>
                    <div class="bqy_item">Python</div>
                </div>
            </div>
        </div>
    </section>

    <!-- 页脚 -->
    <footer id="footer">
        <div>
            @ 2025 博客空间 保留所有权利
        </div>
    </footer>

    <!-- 鼠标点击文字显示效果js代码-->
    <script src="../public_static/js/mouse_click_effect.js"></script>

    <script>
    // 当前页码
    let currentPage = 1;
    // 每页显示数量
    const pageSize = 3;
    // 当前分类
    let currentCategory = null;
    // 当前搜索词
    let currentSearch = null;

    // 页面加载完成后执行初始化操作
    document.addEventListener('DOMContentLoaded', async () => {
        // 加载文章列表
        await loadArticles();
        // 加载分类统计
        await loadCategoryStats();
        // 加载热门文章
        await loadPopularArticles();
        
        // 绑定事件监听
        bindEvents();
    });

    // 加载文章列表
    async function loadArticles() {
        // 平滑滚动到页面顶部
        window.scrollTo({
        top: 0,
        behavior: 'smooth'
        });

        try {
            // 调用electronAPI获取文章数据
            const result = await window.electronAPI.getArticles({
                page: currentPage,
                limit: pageSize,
                category: currentCategory,
                search: currentSearch
            });
            
            // 渲染文章列表
            renderArticles(result.articles);
            // 渲染分页导航
            renderPagination(result.totalPages);
        } catch (error) {
            console.error('加载文章失败:', error);
        }
    }

    // 函数用于移除HTML标签，提取纯文本
    function stripHtmlTags(html) {
        if (!html) return '';
        const tempDiv = document.createElement('div');
        tempDiv.innerHTML = html;
        return tempDiv.textContent || tempDiv.innerText || '';
    }

    // 渲染文章列表
    function renderArticles(articles) {
        // 平滑滚动到页面顶部
        window.scrollTo({
        top: 0,
        behavior: 'smooth'
        });
        
        const articleCardContainer = document.getElementById('articleCardContainer');
        // 清空现有内容
        articleCardContainer.innerHTML = '';
        
        // 如果没有文章，显示提示信息
        if (articles.length === 0) {
            articleCardContainer.innerHTML = '<div style="padding: 20px;">没有找到相关文章</div>';
            return;
        }

        // 定义分类与颜色的映射关系
        const categoryColors = {
            '技术': 'rgb(13, 110, 253)',
            '生活': 'rgb(25, 135, 84)',
            '旅行': 'rgb(13, 202, 240)',
            '美食': 'rgb(255, 193, 7)',
            '默认': 'rgb(13, 202, 240)'      // 原始默认色
        };
            
        // 遍历文章数据，创建文章卡片
        articles.forEach(article => {
            const articleElement = document.createElement('div');
            articleElement.className = 'article_content';
            
            // 格式化日期
            const date = new Date(article.create_time);
            const formattedDate = `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`;

            // 获取当前分类对应的颜色，默认使用预设的默认色
            const categoryColor = categoryColors[article.category] || categoryColors['默认'];
            
            // 设置文章卡片HTML内容
            articleElement.innerHTML = `
                <div class="article_pic">
                    <img src="${article.cover_url || './static/images/fengmian/默认封面1.jpg'}" alt="文章封面">
                </div>
                <div class="article_info">
                    <div class="article_card_top">
                        <div class="article_category" style="background-color: ${categoryColor}">${article.category}</div>
                        <i class="fas fa-calendar"></i>
                        <div class="article-date">${formattedDate}</div>
                    </div>
                    <div class="article_title">${article.title}</div>
                    <div class="article_expert">${article.content ? stripHtmlTags(article.content).substring(0, 80) + '...' : ''}</div>
                    <div class="article_author">
                        <div class="article_card_bottom">
                            <img src="${article.author_avatar_url || './static/images/touxiang/默认头像1.jpg'}" alt="作者头像">
                            <div class="author_name">${article.author}</div>
                        </div>
                        <a href="#" class="reading_more" data-id="${article.article_id}">阅读更多</a>
                    </div>
                </div>
            `;
            
            articleCardContainer.appendChild(articleElement);
            
            // 绑定阅读更多按钮事件
            const readMoreBtn = articleElement.querySelector('.reading_more');
            readMoreBtn.addEventListener('click', (e) => {
                e.preventDefault();
                showArticleDetail(article.article_id);
            });
        });
    }

    // 渲染分页导航
    function renderPagination(totalPages) {
        const paginationContainer = document.getElementById('paginationContainer');
        paginationContainer.innerHTML = '';
        
        // 创建上一页按钮
        const prevBtn = document.createElement('a');
        prevBtn.href = '#';
        prevBtn.textContent = '上一页';
        prevBtn.disabled = currentPage <= 1;
        if (prevBtn.disabled) {
            prevBtn.style.opacity = '0.5';
            prevBtn.style.pointerEvents = 'none';
        }
        prevBtn.addEventListener('click', (e) => {
            e.preventDefault();
            if (currentPage > 1) {
                currentPage--;
                loadArticles();
            }
        });
        paginationContainer.appendChild(prevBtn);
        
        // 添加页码信息
        const pageInfo = document.createElement('span');
        pageInfo.style.display = 'flex';
        pageInfo.style.alignItems = 'center';
        pageInfo.style.minWidth = '80px';
        pageInfo.style.justifyContent = 'center';
        pageInfo.textContent = `第 ${currentPage} 页 / 共 ${totalPages} 页`;
        paginationContainer.appendChild(pageInfo);
        
        // 创建下一页按钮
        const nextBtn = document.createElement('a');
        nextBtn.href = '#';
        nextBtn.textContent = '下一页';
        nextBtn.disabled = currentPage >= totalPages;
        if (nextBtn.disabled) {
            nextBtn.style.opacity = '0.5';
            nextBtn.style.pointerEvents = 'none';
        }
        nextBtn.addEventListener('click', (e) => {
            e.preventDefault();
            if (currentPage < totalPages) {
                currentPage++;
                loadArticles();
            }
        });
        paginationContainer.appendChild(nextBtn);
    }

    // 加载分类统计数据
    async function loadCategoryStats() {
        // 平滑滚动到页面顶部
        window.scrollTo({
        top: 0,
        behavior: 'smooth'
        });
        
        try {
            // 获取分类统计数据
            const categories = await window.electronAPI.getCategoryStats();
            const categoryContainer = document.getElementById('categoryContent');
            categoryContainer.innerHTML = '';

            // 定义分类与颜色、图标的映射关系
            const categoryConfig = {
                '技术': { 
                    color: 'rgb(13, 110, 253)',
                    icon: 'fas fa-code'  // 技术分类使用代码图标
                },
                '生活': { 
                    color: 'rgb(25, 135, 84)',
                    icon: 'fas fa-home'  // 生活分类使用房屋图标
                },
                '旅行': { 
                    color: 'rgb(13, 202, 240)',
                    icon: 'fas fa-location-dot'     // 旅行分类使用地图图标
                },
                '美食': { 
                    color: 'rgb(255, 193, 7)',
                    icon: 'fas fa-utensils'   // 美食分类使用食物图标
                },
                '默认': { 
                    color: 'rgb(13, 202, 240)',
                    icon: 'fas fa-folder'      // 默认分类使用文件夹图标
                }
            };
            
            // 遍历分类数据，创建分类项
            categories.forEach(category => {
                // 获取当前分类对应的配置
                const config = categoryConfig[category.category] || categoryConfig['默认'];

                const categoryElement = document.createElement('div');
                categoryElement.className = 'wzfl_info';
                categoryElement.innerHTML = `
                    <a href="#" data-category="${category.category}">
                        <i class="${config.icon}"></i>${category.category}
                    </a>
                    <div class="number" style="background-color: ${config.color}">${category.count}</div>
                `;
                
                categoryContainer.appendChild(categoryElement);
                
                // 绑定分类点击事件
                const categoryLink = categoryElement.querySelector('a');
                categoryLink.addEventListener('click', (e) => {
                    e.preventDefault();
                    // 切换到列表视图
                    document.getElementById('articleDetail').style.display = 'none';
                    document.getElementById('contentShow').style.display = 'flex';
                    
                    currentCategory = category.category;
                    currentPage = 1; // 重置到第一页
                    loadArticles();
                });
            });
        } catch (error) {
            console.error('加载分类失败:', error);
        }
    }

    // 加载热门文章
    async function loadPopularArticles() {
        try {
            // 获取热门文章数据，限制3篇
            const popularArticles = await window.electronAPI.getPopularArticles(3);
            const popularContainer = document.getElementById('popularArticlesContent');
            popularContainer.innerHTML = '';
            
            // 遍历热门文章数据，创建热门文章项
            popularArticles.forEach(article => {
                const date = new Date(article.create_time);
                const formattedDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
                
                const articleElement = document.createElement('div');
                articleElement.className = 'lmwz_new';
                articleElement.innerHTML = `
                    <a href="#" class="lmwz_new_title" data-id="${article.article_id}">${article.title}</a>
                    <div class="lmwz_time">${formattedDate}</div>
                `;
                
                popularContainer.appendChild(articleElement);
                
                // 绑定热门文章点击事件
                articleElement.querySelector('a').addEventListener('click', (e) => {
                    e.preventDefault();
                    showArticleDetail(article.article_id);
                });
            });
        } catch (error) {
            console.error('加载热门文章失败:', error);
        }
    }

    // 显示文章详情
    async function showArticleDetail(articleId) {
        // 平滑滚动到页面顶部
        window.scrollTo({
        top: 0,
        behavior: 'smooth'
        });
        
        try {
            // 根据文章ID获取文章详情
            const article = await window.electronAPI.getArticleById(articleId);
            if (!article) {
                alert('文章不存在或已被删除');
                return;
            }
            
            // 隐藏列表，显示详情
            document.getElementById('contentShow').style.display = 'none';
            document.getElementById('articleDetail').style.display = 'flex';
            
            // 格式化日期
            const date = new Date(article.create_time);
            const formattedDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
            
            // 填充详情内容
            document.getElementById('articleTitle').textContent = article.title;
            document.getElementById('authorAvatar').src = article.author_avatar_url || './static/images/touxiang/默认头像1.jpg';
            document.getElementById('authorName').textContent = article.author;
            document.getElementById('publishDate').textContent = formattedDate;
            document.getElementById('readTime').textContent = `${article.read_time || 5}分钟阅读`;
            document.getElementById('viewCount').textContent = `${article.views || 0}阅读`;
            document.getElementById('articleContent').innerHTML = article.content || '暂无内容';
        } catch (error) {
            console.error('加载文章详情失败:', error);
        }
    }

    // 绑定所有事件监听
    function bindEvents() {
        // 返回列表按钮事件
        document.getElementById('backToListBtn').addEventListener('click', (e) => {
            e.preventDefault();
            document.getElementById('articleDetail').style.display = 'none';
            document.getElementById('contentShow').style.display = 'flex';
        });
        
        // 搜索功能
        const searchInput = document.getElementById('searchInput');
        const searchBtn = document.getElementById('searchBtn');
        
        searchBtn.addEventListener('click', () => {
            currentSearch = searchInput.value.trim();
            currentPage = 1;
            loadArticles();
        });
        
        // 按回车键搜索
        searchInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') {
                currentSearch = searchInput.value.trim();
                currentPage = 1;
                loadArticles();
            }
        });
        
        // 导航栏分类点击事件
        document.querySelectorAll('#navRight .nav_item').forEach(item => {
            item.addEventListener('click', (e) => {
                e.preventDefault();
                // 无论当前在列表还是详情页，都切换到列表视图
                document.getElementById('articleDetail').style.display = 'none';
                document.getElementById('contentShow').style.display = 'flex';
                
                if (item.textContent === '首页') {
                    currentCategory = null;
                } else {
                    currentCategory = item.textContent;
                }
                currentSearch = null;
                currentPage = 1;
                loadArticles();
            });
        });

    }


</script>
</body>
</html>